<?php
include("../db_connect.php");
?>


<script>
var limiter2 = 0;
$(document).ready(function () {

$("#accordion_acc").accordion({heightStyle: "content",collapsible: true});

$("#addpictures2").click(function () {
		if(limiter <=6){
		
			var a = '</br> <div><img id="img_prev_'+limiter2+'" src="#"/></div><input type="file" name="image[]" id="image" onchange="readURL22(this);"></br>'
			
			$("#addmorepicture2").append(a);
		
		}
		else{
		alert("you can only upload 6 picture");
		}
		return false;
		
	});
$("#abrand2").change(function () {
		var id = $(this).attr("value");
		var model="model";
		$("#amodel2").empty().load("admin/selection.php?command="+model +"&modelid="+id);
	
	});
	
$("#registerButton2").click(function () {

var opttype2 = $("#types2");
var optbrand = 	$("#abrand2");
var model = $("#amodel2");
var name = $("#name2");
var description = $("#description2");
var condition = $("#conditions2");
var fuel = $("#fuel2");
var transmission = $("#transmission2");
var year = $("#year2"); 
var price = $("#price2");
var quantity = $("#quantity2");
var cparts = $("#part2");

	
	if(opttype2.val() ==  "Select" || opttype2.val() == "0"){

	alert("Select a type");
	opttype2.focus();
	return false;
	}
	else if(optbrand.val() ==  "Select" || optbrand.val() ==  "0"){
	alert("Select a brand");
	optbrand.focus();
	return false;
	}
	else if(model.val() ==  "Select" || model.val() ==  ""){
	alert("Select a model");
	model.focus();
	return false;
	}
	else if(name.val() ==  "" || name.val() ==  " "){
	alert("Please input a name");
	name.focus();
	return false;
	}
	else if(description.val() ==  "" || description.val() ==  " "){
	alert("Please input your description");
	description.focus();
	return false;
	}
	else if(cparts.val() ==  "Select" || cparts.val() ==  "0"){
	alert("Select A parts");
	cparts.focus;
	return false;
	}
	else if(year.val() ==  "Select" || year.val() ==  "0"){
	alert("Select year");
	year.focus;
	return false;
	}
	else if(price.val() ==  "" || price.val() == " "){
	alert("Please input quantity");
	price.focus();
	return false;
	}
	else if(isNaN(price.val())){
	alert("Price only accept No.");
	price.focus();
	return false;
	}
	else if(quantity.val() ==  ""|| quantity.val() ==  " "){
	alert("Please input quantity");
	quantity.focus();
	return false;
	}
	else if(isNaN(quantity.val())){
	alert("Price only quantity No.");
	quantity.focus();
	return false;
	}
	else{
	 return true;
	}
	

});	



$("#report_acc").click(function(){

window.open("reports/acc_reports.php");
	
});



});

function readURL22(input) {
	var b = '#img_prev_'+limiter2;
	
	if (input.files && input.files[0]) {
		var reader = new FileReader();
		reader.onload = function (e) {
			$(b).attr('src', e.target.result).width(300).height(120);
			limiter++;
		};
			reader.readAsDataURL(input.files[0]);
	}
}

function autodelete(value){

if(confirm("Do you want to delete this?")){
$.ajax({
	
	url:"admin/modifyData.php?category=auto&action=delete&pid="+value,
	success:function(data){
		if(data){
		alert("Successful Delete");
		$("#auto_cars").html(loader).load("admin/viewAuto.php");
		}
		else{
			alert("Unsuccessful Delete");
		}
		
	}


});
}



}
function autoEdit(value){
	$("#edit_acc").load("admin/editmsgbox.php?pid="+value);
}


	
	
</script>

<style>

h4 a{
font-size:12px;
}
#auto_cars tr{ 
	display: table;            /* this makes borders/margins work */
	border: 1px solid black;
	width:100%;
	margin: 2px 0px 0px 0px;
}
</style>
<div id="msgbox"></div>
<div id="accordion_acc" align="center">
	<h4 style="color:white">Add New Parts</h4>
	<div>
			<div id="auto" class="auto">

	<div id="steps">
		<form id="formElem" name="formElem" action="admin/addaccessories.php" method="post" enctype="multipart/form-data">
			<fieldset class="step">
				<legend>Item Name</legend>
				<p>
					<label for="types">Type</label>
					<select id="types2" value="types2"  name="types">
					<?php 
						$sql = mysql_query("SELECT * FROM tbltypes");
						$opt2 = '<option id="opttype" name="none" value="0">Select</option> ';
						while($row = mysql_fetch_array($sql) ){
							$opt2 .= '<option id="opttype" value="'.$row["types"].'" >'.$row["types"].'</option>';
						}
						echo $opt2;
					?>
					</select>
					
					
				</p>
				<p>
					<label for="brand">Brand</label>
					<select id="abrand2" value="brand" name="brand">
					<?php 
						$sql = mysql_query("SELECT * FROM tblbrand");
						$opt = '<option id="optbrand" name="none" value="0">Select</option> ';
						while($row = mysql_fetch_array($sql) ){
							$opt .= '<option id="optbrand" name="'.$row["brand"].'" value="'.$row["id"].'" >'.$row["brand"].'</option>';
						}
						echo $opt;
					?>
					</select>
				</p>
				<p>
					<label for="Model">Model</label>
					<select id="amodel2" value="model" name="model">
					
					</select>
					
				</p>
					<p>
						<label for="part">Part</label>
						<select id="part2" value="parts" name="part">
						<?php 
							$sql = mysql_query("SELECT * FROM tblparts");
							$opt = '<option id="optbrand" name="none" value="0">Select</option> ';
							while($row = mysql_fetch_array($sql) ){
								$opt .= '<option id="optpart" value="'.$row["parts"].'" >'.$row["parts"].'</option>';
							}
							echo $opt;
						?>
						</select>
					</p>
				<p>
					<label for="Name">Name</label>
					<input type="text" id="name2" name="name" AUTOCOMPLETE=OFF />
				   
				</p>
			</fieldset>
			
			
			<fieldset class="step">
				<legend>Description</legend>
				<p>
					<label for="description">Description</label>
					<textarea style="width: 590px; height: 123px;" id="description2" value="description" name="description"></textarea>
				</p>
					<p>
					<label for="year">Year</label>
					<select id="year2" name="year">
						<option>Select</option>
						<option>2006</option>
						<option>2007</option>
						<option>2008</option>
						<option>2009</option>
						<option>2010</option>
						<option>2011</option>
						<option>2012</option>
					</select>
				</p>
				<p>
					<label for="price">Price</label>
					<input id="price2" name="price" type="number" AUTOCOMPLETE=OFF />
				</p>
				<p>
					<label for="quantity">Quantity</label>
					<input id="quantity2" name="quantity" type="number" AUTOCOMPLETE=OFF />
				</p>
				
				
			</fieldset>
			
			<fieldset class="step">
							<p>
								<legend>Color</legend>	
										<label for="color"></label>
										<select id="color" name="color">
											<option value="">Select</option>
											<?php 
												$sql = mysql_query("SELECT * FROM tblcolor")or die(mysql_error());
												while($row = mysql_fetch_array($sql)){
													echo '<option value="'.$row['color'].'">'.$row['color'].'</option>';
												}
											
											?>
										
										</select>
										</p>
								<p>
									<legend>Payment</legend>
									  <label for="payment" ></label>
										<select id = "modeofpayment" name="modeofpayment">
											<option value="0">Select Payment</option>
											<option value="Cash">Cash</option>
											<option value="Installment">Installment</option>
											
										</select>
								</p>
								
								</fieldset>
								
								
			
			<fieldset class="step">
				<legend>Image</legend>
				<p id="addmorepicture2">
					
				</p>
				<p>
					<button id="addpictures2">Add picture</button>
				</p>
			</fieldset>
			<fieldset class="step">
				<legend>Confirm</legend>
				<p>
					Please fill up all the missing fields before you proceed
				</p>
				<p class="submit">
					<button id="registerButton2" type="submit" name = "submit">Submit</button>
				</p>
			</fieldset>
		</form>
	</div>
						
					</div>

			</div>
		
	
	
	<h4>View Parts</h4>
	<div id="edit_acc">
		<div id="searchbox" align="left">
		<!--search div-->
	
			<div class="headersearch ">
				<button id="report_acc">Generate Report</button>
			</div>
			
				
		<!--end search div-->		
		</div>
		<div id="auto_cars" style="overflow:auto">
		<?php 
			include("../class/objName.php");
			//include();
			$stock = "";
			$sql = "SELECT * FROM tblswaping where addoff = '1' AND categories like'%Acccessories%'  order by id DESC";
			$result = mysql_query($sql)or die(mysql_error);
			$brand_data = "";
			if(mysql_num_rows($result)<1 ){
				echo '<div style="padding:10px;"><h3 style="color:white;" >No Item Found</h3></div>';
				die();
			}
			
			
			$obj = new objName();
			
			echo "<table border='0' width='100%' style=''>";
			echo "<tr style='background-color:gray; color:white;' > <td width='270px'>Title</td> <td >Description</td> <td>Content</td> </tr>";		
			while($row = mysql_fetch_array($result)){
					$img = $obj->displayimg($row['filename'],true);
					
					if($row['quantity']<1){
						echo "	<tr style=' border: 1px solid white;' class='odd'> ";
						$stock =" <font style='color:red'> OUT OF STOCK </font>";
					}
					else{
						echo "	<tr style=' border: 1px solid white;' class='even'> ";
						$stock = $row['quantity'];
					}
					
					
					echo "<td valign='top' width='100px'>
						
						<img id='' style='width:220px; height:140px;' src='images/vehicles/$img'>
						<div>Posted by:<a href='#' style='color:red;' > ".$row['fname'] ." ".$row['lname'] . "</a>";                                            
					echo "<p>Name:".$row['name']."</br> Time posted:".$row['timepost']."</br>
					<a  id='auto_".$row['id']."' onclick='autoEdit(".$row['id'].")'   name='".$row['id']."' href='#msgbox' style='color:red'>Edit</a>|
					<a 	id='auto_".$row['id']."' onclick='autodelete(".$row['id'].")' name='".$row['id']."' href='#msgbox' style='color:red'>Delete</a></p>";
					echo "</div></td>";
					echo"<td valign='top' width='120px'><div width='120'>";
						
						if($row['categories']== "Acccessories"){
							
							echo"Item-Code:Acc-".$row['id']."</br>";
							echo"Qty:".$stock."</br>";
							echo"Price: ".$row['price']."</br>";
							echo"Brand: ".$row['brand']."</br>";
							echo"Model: ".$row['model']."</br>";
							echo"Condition: ".$row['conditions']."</br>";
							echo"Parts: ".$row['cparts']."</br>";
						}
						
						
							
					echo "</div></td>";
					
					echo"<td valign='top'><div  style='height:260px; width:264px; border-left:1px white; overflow:auto;'><p align='justify'>" .$row['description']."</p></div></td>";
				echo"</tr>";
		
			}
			
			echo "</table>";
		
		
		?>				
		</div>
	</div>
	
	
</div>
	
							